class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            countdown:60,
            navhtml: [],
            disheshtml: [],
            clicknavid: 1,
            checkid:-1,
            amount:0,
            name:'',
            code:'',
            navList: [
                {
                    lefticon: './src/yue_icon.png',
                    content: '余额支付',
                },
                {
                    lefticon: './src/gh_icon.png',
                    content: '工行收银台',
                },
                // {
                //     lefticon: './src/radio.png',
                //     content: '支付宝',
                // },
                // {
                //     lefticon: './src/radio.png',
                //     content: '微信',
                // },
            ],
        };
    }

    settime(){
        let {countdown} = this.state,that = this;
        if (countdown == 0) {
            //  $('#yzmbtn').attr("disabled",false); 
            $('.right').text("获取验证码");
            this.setState({countdown:60})
        } else {
            // $('#yzmbtn').attr("disabled", true); 
            $('.right').text("重新发送(" + countdown + ")");
            countdown--;
            this.setState({countdown},()=>{
                setTimeout(function () {
                    that.settime()
                }, 1000)
            })
        }
    }

    click(e){
      //  let list1 = this.state.navList;
        // let {navList} = this.state;
        // navList.map((x,i)=>{ return x.checked = i==e})
        this.setState({checkid:e})

    }
    confirm(){
        let name = $('.name').val() || "",code = $('.code').val() || "", {id} = this.state,err='';
        if(name.length==0) err = '姓名输入有误'
        if(code.length==0) err = '考生号输入有误'
        if(err!=''){
            alert(err)
        }else{
            bind({userid:id,name,code},res=>{
                if(res.issuccess==1){
                    alert('绑定成功')
                    localStorage.setItem('user',JSON.stringify(res.user))
                    window.location.href='./main.html'
                }else{
                    alert(res.msg)
                }
            })
        }
       
     
    }

    yzclick(){
        var phone = $('.phone').val() || "";
        if (phone.length != 11) {
            alert('手机号输入有误')
        } else {
            if ($('.right').text() == '获取验证码') {
    
                var phone = $('.phone').val() || "";
                sendsms(phone, succ => {
                    if (succ.result == 'successful') {
                       this.settime()
                    }else{
                        alert(succ.msg)
                    }
                })
            }
        }
    }


    componentDidMount() {
        if(Constant.SWITCH_VCONSOLE){
            new VConsole();
        }
        let id = GetQueryString('id')
        this.setState({id})
    }
    render() {

        let { name,checkid,memberTotalAmount, amount} = this.state;

        return (
            <div className="all">
                 <div className="table">
                    <div className="phoneitem">
                     <input type="text"   placeholder='请填写姓名' className="name" />
                    </div>
                </div>
                <div className="yzmitem">
                    <input type="text"  placeholder='请填写考生号'  className="code" />
                    {/* <p onClick={this.yzclick.bind(this)} className="right">获取验证码</p> */}
                </div>
               
                <div onClick={()=>{this.confirm()}} className="btn">绑定</div>
            </div>
        )
    }
}

ReactDOM.render(
    <div>
        {/* <TopLine /> */}
        <div id='body'>
            {/* <LeftMenu code='banner' /> */}
            <Main />
        </div>
    </div>
    // <Barrage />
    , $('.container')[0]
)